import 'package:enterprise_v6_app/app/core/http/http.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/data/entities/application/education/couser_center/lecturer_detail_entity.dart';
import 'package:enterprise_v6_app/app/data/entities/application/education/couser_center/textbook_detail_entity.dart';
import 'package:get/get.dart';

///课程介绍introduction
class TrainIntroductionController extends GetxController {
  String? itemId = '';
  String? textbookLecturerId;

  /// 更多bool
  RxBool showMore = true.obs;

  LecturerDetailEntity? lecturerDetailEntity;
  TextbookDetailEntity? textbookDetailEntity;

  @override
  void onInit() {
    super.onInit();
    if (Get.arguments['id'] != null) {
      itemId = Get.arguments['id'] as String;
    }
    if (Get.arguments['textbookLecturerId'] != null) {
      textbookLecturerId = Get.arguments['textbookLecturerId'] as String;
    }
    //查询讲师详情
    lecturerDetail();
    //查询课程详情
    textbookDetail();
  }

  ///查询讲师详情
  void lecturerDetail() async {
    final res = await HttpUtil().generateGetRequest<LecturerDetailEntity>(
      Interface.lecturerDetail,
      queryParameters: {
        'id': textbookLecturerId,
      },
    ).execute();
    res.onSuccess((result) {
      if (result.data != null) {
        lecturerDetailEntity = result.data!;
        update();
      }
    });
  }

  ///查询课程详情
  void textbookDetail() async {
    final res = await HttpUtil().generateGetRequest<TextbookDetailEntity>(
      Interface.textbookDetail,
      queryParameters: {
        'textbookId': itemId,
      },
    ).execute();
    res.onSuccess((result) {
      if (result.data != null) {
        textbookDetailEntity = result.data!;
        update();
      }
    });
  }

  //师资力量点赞
  void onClickTrainLikeTeacher() async {
    final res = await HttpUtil().generateGetRequest(
      Interface.likeOrCleanLike,
      queryParameters: {'id': textbookLecturerId},
    ).execute();
    res.onSuccess((result) {
      //查询讲师详情
      lecturerDetail();
    });
  }
}
